﻿using System.Linq;
using Rated.DAL.Db;
using System.Web.Security;

namespace Rated.Website.Helpers
{
    public static class UserHelper
    {
        public static MembershipUser Current
        {
            get { return Membership.GetUser(); }
        }

        public static UserProfile UserProfile
        {
            get
            {
                var mu = Current;
                if (mu == null) return null;
                var userid = (int) (mu.ProviderUserKey ?? 0);
                return new RatedEntities().UserProfiles.FirstOrDefault(o => o.UserId == userid);
            }
        }
        public static string FullName
        {
            get
            {
                var up = UserProfile;
                var result = string.Empty;
                if (up == null)
                    return result;
                if (!string.IsNullOrEmpty(up.Title))
                    result += up.Title;

                if (!string.IsNullOrEmpty(up.FirstName))
                {
                    if (result != string.Empty)
                        result += ' ';
                    result += up.FirstName;
                }
                if (!string.IsNullOrEmpty(up.LastName))
                {
                    if (result != string.Empty)
                        result += ' ';
                    result += up.LastName;
                }
                return result;
            }
        }
    }
}